package com.woquyin.interceptor;

import java.util.Enumeration;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.HttpKit;

public class ParamInterceptor implements Interceptor {

	public static final String REQUEST_JSON = "requestJson";

	@Override
	public void intercept(Invocation inv) {
		Controller c = inv.getController();
//		String jsonString = HttpKit.readData(c.getRequest());
		System.out.println(c.getRequest());
		String jsonString = "";
		Enumeration keyArr = c.getRequest().getParameterNames();
		while(keyArr.hasMoreElements()){
			String keyName = (String)keyArr.nextElement();
			jsonString += keyName+":\""+c.getRequest().getParameter(keyName)+"\",";
		}
		if(!jsonString.equals("")){
			jsonString = jsonString.	substring(0,jsonString.length()-1);
			jsonString="{"+jsonString+"}";
		}
		c.setAttr(REQUEST_JSON, jsonString);
		inv.invoke();
	}

}
